/*
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package de.chimos.property.compiler.passone;

import static org.objectweb.asm.Opcodes.ASM4;

import java.util.List;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.FieldVisitor;

import de.chimos.property.annotation.PropertyHint;
import de.chimos.property.compiler.Config;
import de.chimos.property.compiler.PropertyInfo;

/**
 * @author Niklas Hofmann
 */
public class PassOneFieldVisitor extends FieldVisitor {
    
    private final String className;
    private final String propertyName;
    
    private final String signature;
    private final String signatureGeneric;
    
    private final int fieldAccessLevel;
    
    private final List<PropertyInfo> properties;
    
    private final Config config;
    
    public PassOneFieldVisitor(String className, String propertyName, String signature, String signatureGeneric, int fieldAccessLevel, List<PropertyInfo> properties, Config config)
    {
        super(ASM4);
        
        this.className = className;
        this.propertyName = propertyName;
        
        this.signature = signature;
        this.signatureGeneric = signatureGeneric;
        
        this.fieldAccessLevel = fieldAccessLevel;
        
        this.properties = properties;
        
        this.config = config;
    }

    @Override
    public AnnotationVisitor visitAnnotation(String desc, boolean visible)
    {
        if(desc.equals("L"+PropertyHint.class.getName().replace('.', '/')+";"))
        {
            return new PassOneFieldAnnotationVisitor(className, propertyName, signature, signatureGeneric, fieldAccessLevel, properties, config);
        }
        
        return null;
    }
    
}
